package io.jt808.proto.cmd;


import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 摄像头立即拍摄命令
 */
@Proto("8801")
@Data
public class JT8801 implements IProto {
    /**
     * 通道ID
     */
    private byte channelId;

    /**
     * 拍摄命令 0表示停止拍摄；0xFFFF表示录像；其它表示拍照张数
     */

    private short photoCommand;

    /**
     * 拍照间隔/录像时间
     */

    private short photoTimeInterval;

    /**
     * 保存标志
     */
    private byte storeFlag;

    /**
     * 分辨率
     */
    private byte resolution;

    /**
     * 图像/视频质量
     */
    private byte quality;

    /**
     * 亮度
     */
    private short brightness;

    /**
     * 对比度
     */
    private short contrast;

    /**
     * 饱和度
     */
    private short saturation;

    /**
     * 色度
     */
    private short chroma;

    public final byte[] writeToBytes() {
        AutoBuffer buffer = new AutoBuffer();
        buffer.writeByte(channelId);
        buffer.writeShort(photoCommand);
        buffer.writeShort(photoTimeInterval);
        buffer.writeByte(storeFlag);
        buffer.writeByte(resolution);
        buffer.writeByte(quality);
        buffer.writeByte(brightness);
        buffer.writeByte(contrast);
        buffer.writeByte(saturation);
        buffer.writeByte(chroma);
        return buffer.array();
    }

    public final void readFromBuf(AutoBuffer buffer) {
        channelId = buffer.readByte();
        photoCommand = buffer.readShort();
        photoTimeInterval = buffer.readShort();
        storeFlag = buffer.readByte();
        resolution = buffer.readByte();
        quality = buffer.readByte();
        brightness = buffer.readUnsignedByte();
        contrast = buffer.readUnsignedByte();
        saturation = buffer.readUnsignedByte();
        chroma = buffer.readUnsignedByte();
    }
//    public static void main(String[] args){
//        byte[] bytes=new byte[]{
//                0x01,
//                (byte) 0xFF, (byte) 0xFF,
//                (byte) 0x00, (byte) 0xFF,
//                0x01,
//                0x01,
//                0x05,
//                0x01,
//                0x07,
//                0x07,
//                (byte) 0xFF
//        };
//        JT8801 jt8801=new JT8801();
//        jt8801.readFromBuf(new AutoBuffer(bytes));
//        System.out.println(new String(bytes).equals(new String(jt8801.writeToBytes())));
//    }
}